/*
 * @Author: zhangfeng
 * @Date: 2022-09-06 16:02:42
 * @LastEditTime: 2024-01-16 18:19:09
 * @LastEditors: zhangfeng
 * @Description:
 * @FilePath: \nodeapi\src\router\goods.router.js
 * © 2023 张峰，All rights reserved.
 */
const Router = require("koa-router");
const { hasNotAdminPermission } = require("../constants/err.type");

const {
  upload,
  create,
  update,
  remove,
  restore,
  findAll,
} = require("../controller/goods.controller");

const { auth, hadAdminPermission } = require("../middleware/auth.middleware");
const { validator } = require("../middleware/goods.middleware");

const router = new Router({
  prefix: "/goods",
});

// 上传图片
router.post("/upload", upload);

// 发布商品
router.post("/", auth, hadAdminPermission, validator, create);

// 修改商品
router.put("/:id", auth, hadAdminPermission, validator, update);

// 删除商品
// router.delete("/:id", auth, hadAdminPermission, remove)

// 商品下架
router.post("/:id/off", auth, hadAdminPermission, remove);
// 商品上架
router.post("/:id/on", auth, hadAdminPermission, restore);

// 获取商品列表
router.get("/", findAll);

module.exports = router;
